package band.wukong.practice.webservice.kh.sample09;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.jws.WebService;
import javax.xml.ws.soap.MTOM;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author wukong(wukonggg@139.com)
 */
@WebService(
    endpointInterface = "band.wukong.practice.webservice.kh.sample09.BinaryService",
    targetNamespace = BinaryConst.SERVICE_NS,
    serviceName = BinaryConst.SERVICE_NAME,
    portName = BinaryConst.PORT_NAME
)
@MTOM
public class BinaryServiceImpl implements BinaryService {

    private static final Logger logger = LoggerFactory.getLogger(BinaryServiceImpl.class);

    @Override
    public void upload(byte[] file) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("D:/2.png");
            fos.write(file);
            fos.flush();

        } catch (IOException e) {
            logger.error(e.getMessage());
            e.printStackTrace();

        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                logger.error(e.getMessage());
                e.printStackTrace();
            }
        }
    }
}
